package com.example.week2_try2;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity2 extends AppCompatActivity implements View.OnClickListener{

    TextView score_sum=findViewById(R.id.team1_score);
    int score = 0;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);
        Button btn3 = findViewById(R.id.points_3);
        Button btn2=findViewById(R.id.points_2);
        Button btn1=findViewById(R.id.points_1);
        btn3.setOnClickListener(this);//表示当前类运行的对象实现监听接口的方法
        //btn.getId()

    }

    @Override
    public void onClick(View view) {
        score+=3;
        String result = String .format("%d",score);
        score_sum.setText(result);
    }

    public void btn(View V){
        if(V.getId()==R.id.points_3){
            score+=3;
        }
        else if(V.getId()==R.id.points_2){
            score+=2;
        }
        else if(V.getId()==R.id.points_1){
            score+=1;
        }
        else {
            score=0;
        }

        String result = String .valueOf(score);
        score_sum.setText(result);
    }

    public void btn2(View V){
        score+=2;
        String result = String .format("%d",score);
        score_sum.setText(result);
    }

    public void reset(View V){
        score=0;
        String result = String .format("%d",score);
        score_sum.setText(result);
    }
}